package com.wb3.meta.common.utils;

import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;

public class GoogleVerifyUtils {
    public static boolean googleVerify(String token){
        if (StringUtils.isBlank(token)) {
           return false;
//            return ResultT.fail("Google recaptcha validation failed", "");
        }

        String apiUrl = "https://www.google.com/recaptcha/api/siteverify";
        Map<String, String> map = new HashMap<>();
        map.put("secret", "6LdfW40iAAAAAOavaNB-SZL1x6pC-5wzh7JZ_EMk");
        map.put("response", token);
        String res = HttpUtils.post(apiUrl, null, map, true);
        JSONObject jsonObject = JSONObject.parseObject(res);
        if(!jsonObject.getBoolean("success")){
//            return ResultT.fail("Google recaptcha validation failed", "");
            return false;
        }
        return true;
    }
}
